# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=luv
_pkgname=lib${_realname}
pkgbase=mingw-w64-${_pkgname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_pkgname}"
_pkgver=1.44.2-1
pkgver=${_pkgver/-/_}
pkgrel=1
pkgdesc='Bare libuv bindings for lua (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/luvit/luv'
license=('apache')
depends=("${MINGW_PACKAGE_PREFIX}-luajit"
         "${MINGW_PACKAGE_PREFIX}-libuv")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${_pkgver}.tar.gz"::"${url}/releases/download/${_pkgver}/${_realname}-${_pkgver}.tar.gz")
sha256sums=('3eb5c7bc44f61fbc4148ea30e3221d410263e0ffa285672851fc19debf9e5c30')

prepare() {
  cd "${srcdir}/${_realname}-${_pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_MODULE=OFF \
    -DWITH_SHARED_LIBUV=ON \
    -DLUA_BUILD_TYPE=System \
    ../${_realname}-${_pkgver}

  ${MINGW_PREFIX}/bin/cmake --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake --install ./

  install -Dm644 "${srcdir}/${_realname}-${_pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_pkgname}/LICENSE.txt"
}
